var t = getApp();

Page({
    data: {
        imgUrl: "",
        TabCur: 0,
        scrollLeft: 0,
        emojiItems: [ "熊猫头", "蘑菇头", "红脸蛋", "其他" ],
        ad: {},
        ch: 0
    },
    onLoad: function() {
        var e = this;
        this.setData({
            ad: t.globalData.ad
        }), wx.getSystemInfo({
            success: function(t) {
                var o = 750 / t.screenWidth * t.windowHeight - 80;
                e.setData({
                    ch: o
                });
            }
        }), wx.showLoading({
            title: "加载中"
        });
        var o = this;
        wx.request({
            url: "https://656d-emojimaker-release-7xvun-1301707257.tcb.qcloud.la/emotion/1.json",
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                wx.hideLoading(), o.setData({
                    imgUrl: t.data
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "连接出错，请稍后重试",
                    icon: "none",
                    duration: 2e3
                });
            }
        });
    },
    swiperChange: function(t) {
        if (console.log(t), "touch" == t.detail.source) {
            var e = t.detail.current;
            this.setData({
                TabCur: e
            }), wx.showLoading({
                title: "加载中"
            });
            var o = this;
            wx.request({
                url: "https://656d-emojimaker-release-7xvun-1301707257.tcb.qcloud.la/emotion/" + (e + 1) + ".json",
                header: {
                    "content-type": "application/json"
                },
                success: function(t) {
                    wx.hideLoading(), o.setData({
                        imgUrl: t.data
                    });
                },
                fail: function(t) {
                    wx.showToast({
                        title: "连接出错，请稍后重试",
                        icon: "none",
                        duration: 2e3
                    });
                }
            });
        }
    },
    tabSelect: function(t) {
        this.setData({
            TabCur: t.currentTarget.dataset.id
        }), wx.showLoading({
            title: "加载中"
        });
        var e = this;
        wx.request({
            url: "https://656d-emojimaker-release-7xvun-1301707257.tcb.qcloud.la/emotion/" + (t.currentTarget.dataset.id + 1) + ".json",
            header: {
                "content-type": "application/json"
            },
            success: function(t) {
                wx.hideLoading(), e.setData({
                    imgUrl: t.data
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: "连接出错，请稍后重试",
                    icon: "none",
                    duration: 2e3
                });
            }
        });
    },
    chooseFromAlbum: function() {
        wx.chooseImage({
            count: 1,
            sizeType: [ "compressed" ],
            sourceType: [ "album" ],
            success: function(e) {
                var o = e.tempFilePaths[0];
                t.globalData.selectImageUrl = o, wx.navigateBack({
                    url: "../emotionEdit/emotionEdit?choosedEmoUrl=" + o
                });
            }
        });
    },
    chooseEmotion: function(e) {
        wx.showLoading({
            title: "获取图片"
        });
        var o = this.data.imgUrl[e.currentTarget.dataset.idx];
        wx.downloadFile({
            url: o,
            success: function(e) {
                wx.hideLoading(), t.globalData.selectImageUrl = e.tempFilePath, wx.navigateBack({
                    url: "../emotionEdit/emotionEdit?choosedEmoUrl=" + e.tempFilePath
                });
            },
            fail: function(t) {
                wx.hideLoading(), wx.showToast({
                    title: "连接出错，请稍后重试",
                    icon: "none",
                    duration: 2e3
                });
            }
        });
    },
    onShareAppMessage: function() {
        return {
            title: "一键制作图片、文字、GIF表情包",
            path: "pages/emotionChoose/emotionChoose"
        };
    }
});